<template>

  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['enterprise:construction:add']"
          icon="el-icon-plus"
          plain
          size="small"
          type="primary"
          @click="handleAdd"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['enterprise:construction:edit']"
          :disabled="single"
          icon="el-icon-edit"
          plain
          size="small"
          type="success"
          @click="handleUpdate"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['enterprise:construction:remove']"
          :disabled="multiple"
          icon="el-icon-delete"
          plain
          size="small"
          type="danger"
          @click="handleDelete"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['enterprise:construction:export']"
          :loading="exportLoading"
          icon="el-icon-download"
          plain
          size="small"
          type="warning"
          @click="handleExport"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="constructionList" @selection-change="handleSelectionChange">
      <el-table-column align="center" type="selection" width="55"/>
<!--      <el-table-column align="center" label="企业名称" prop="epId"/>-->
      <el-table-column align="center" label="建设项目名称" prop="pcName"/>
      <el-table-column align="center" label="建设地点" prop="pcAddress"/>
      <el-table-column align="center" label="项目建设周期" prop="pcCycle"/>
<!--      <el-table-column align="center" label="立项报告" prop="pcBeginningReport">
        <template slot-scope="scope" v-if="scope.row.pcBeginningReport">
          <a :href="`${baseUrl}${scope.row.pcBeginningReport}`" target="_blank"
             class="buttonText">{{scope.row.pcBeginningReport.toString().substring(scope.row.pcBeginningReport.lastIndexOf("/") + 1)
            }}</a>
        </template>
      </el-table-column>-->
<!--      <el-table-column align="center" label="项目现状" prop="pcStatus"/>-->
<!--      <el-table-column align="center" label="环评审查意见" prop="pcPlanEnvReviewNum">
        <template slot-scope="scope" v-if="scope.row.pcPlanEnvReviewNum">
          <a :href="`${baseUrl}${scope.row.pcPlanEnvReviewNum}`" target="_blank"
             class="buttonText">{{scope.row.pcPlanEnvReviewNum.toString().substring(scope.row.pcPlanEnvReviewNum.lastIndexOf("/") + 1)
            }}</a>
        </template>
      </el-table-column>-->
      <el-table-column :formatter="typeFormat" align="center" label="环境影响评价文件类别" prop="pcApproval">

      </el-table-column>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['enterprise:construction:edit']"
            size="small"
            @click="handleUpdate(scope.row)"
          >修改
          </el-button>
          <el-button
            v-hasPermi="['enterprise:construction:remove']"
            size="small"
            @click="handleDelete(scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :limit.sync="queryParams.pageSize"
      :page.sync="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />

    <!-- 添加或修改项目建设管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="70%">
      <el-form ref="form" :model="form" :rules="rules" class="clearfix  app-container-construction" label-width="190px">

        <div class="content-left clearfix">
          <div class="title2"><span> </span>基本信息</div>
          <div class="line">
            <el-form-item label="建设项目名称" prop="pcName">
              <el-input v-model="form.pcName" placeholder="请输入建设项目名称"/>
            </el-form-item>
            <el-form-item label="建设地点" prop="pcAddress">
              <el-col>
                <div class="content-address">
                  <el-input v-model="form.pcAddress" placeholder="请输入建设地点"/>
                </div>
              </el-col>
            </el-form-item>
            <el-form-item label="项目代码" prop="pcCode">
              <el-input v-model="form.pcCode" placeholder="请输入项目代码"/>
            </el-form-item>
            <el-form-item label="建设内容、规模" prop="pcContent">
              <el-input  type = "textarea" :rows=5 v-model="form.pcCode" placeholder="请输入项目建设内容、规模"/>
            </el-form-item>
            <el-form-item label="项目建设周期（月）" prop="pcCycle"  type="number">
              <el-input v-model="form.pcCycle" placeholder="请输入项目建设周期（月）"/>
            </el-form-item>
            <el-form-item label="建设性质" prop="pcBuildProperties">
              <el-select v-model="form.pcBuildProperties" placeholder="请选择">
              <el-option
                v-for="dict in typeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
            </el-form-item>
          </div>
          <div class="line">
            <el-form-item label="计划开工时间" prop="pcProjectStartTime">
              <el-date-picker v-model="form.pcProjectStartTime" clearable
                              placeholder="选择计划开工时间"
                              size="small"
                              style="width:100%"
                              type="date"
                              value-format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="预计投产时间" prop="pcEinsatzZiel">
              <el-date-picker v-model="form.pcEinsatzZiel" clearable
                              placeholder="选择预计投产时间"
                              size="small"
                              style="width:100%"
                              type="date"
                              value-format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
          </div>
        </div>
        <div class="content-middle">
          <div class="line">
            <div class="title2"><span> </span>项目信息</div>
            <el-form-item label="建设地点中心坐标(非线性工程)" label-width="50px;">
              <div class="weidu" style="display:flex;">
                <div >
                  <el-input v-model="form.pcNolinearEngLng" placeholder="经度"/>
                </div>
                <div >
                  <el-input v-model="form.pcNolinearEngLat" placeholder="维度"/>
                </div>
              </div>
            </el-form-item>
            <el-form-item label="建设地点中心坐标起点(线性工程)" label-width="1px;">
              <div class="weidu" style="display:flex;" >
                <div >
                  <el-input v-model="form.pcLinearEngLngStar" placeholder="经度"/>
                </div>
                <div >
                  <el-input v-model="form.pcLinearEngLatStar" placeholder="维度"/>
                </div>
              </div>
            </el-form-item>
            <el-form-item label="建设地点中心坐标终点(线性工程)" label-width="1px;">
                <div class="weidu" style="display:flex;">
                  <div>
                    <el-input v-model="form.pcLinearEngLngEnd" placeholder="经度"/>
                  </div>
                  <div>
                    <el-input v-model="form.pcLinearEngLatEnd" placeholder="维度"/>
                  </div>
                </div>
            </el-form-item>
            <el-form-item label="工程长度(千米)" prop="pcEngLength">
              <el-input v-model="form.pcEngLength" placeholder="请输入工程长度(千米)"/>
            </el-form-item>
          </div>
          <div class="line">
            <el-form-item label="规划环评审查机关" prop="pcPlanEnvCensors">
              <el-input v-model="form.pcPlanEnvCensors" placeholder="请输入规划环评审查机关"/>
            </el-form-item>
            <el-form-item label="总投资(万元)" prop="pcTotalInvestment">
              <el-input v-model="form.pcTotalInvestment" placeholder="请输入总投资(万元)"/>
            </el-form-item>
            <el-form-item label="环保投资(万元)" prop="pcEnvironmentInvestment">
              <el-input v-model="form.pcEnvironmentInvestment" placeholder="请输入环保投资(万元)"/>
            </el-form-item>
            <el-form-item label="环境影响评价行业类别" prop="pcEnvSectors">
              <el-cascader
                ref="cascader"
                v-model="hangyeArr"
                :options="hangye"
                :props="{ checkStrictly: true }"
                clearable
                style="width: 100%"
                @change="handleAddressFun">
              </el-cascader>
            </el-form-item>
          </div>
        </div>

        <div class="content-right">
          <div class="title2"></div>
          <div class="line">
            <el-form-item label="现有工程排污许可证编号" prop="pcNowPepNo">
              <el-input v-model="form.pcNowPepNo"/>
            </el-form-item>
            <el-form-item label="环境影响评价文件类别" prop="pcApproval">
              <el-select v-model="form.pcApproval" placeholder="请选择">
                <el-option
                  v-for="dict in typeOptions_hp"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="规划环评审查意见文件文号" prop="pcPlanEnvReviewNum">
              <el-input v-model="form.pcPlanEnvReviewNum"/>
            </el-form-item>
            <el-form-item label="规划环评文件名" prop="pcPlanEnvReviewNum">
              <el-input v-model="form.pcPlanEnvFilename"/>
            </el-form-item>
            <el-form-item label="项目申请类别" prop="pcApplicationCategory">
              <el-input v-model="form.pcApplicationCategory"/>
            </el-form-item>
            <el-form-item label="国民经济行业类型" prop="pcIndustryType">
              <el-input v-model="form.pcIndustryType"/>
            </el-form-item>
<!--            <el-form-item label="立项报告" prop="pcBeginningReport">
              <fileUpload v-model="form.pcBeginningReport"/>
            </el-form-item>-->
<!--            <el-form-item label="立项批复" prop="pcApproval">
              <fileUpload v-model="form.pcApproval"/>
            </el-form-item>-->
            <el-form-item label="规划环评开展情况" prop="pcPlanEnvCase">
              <el-input v-model="form.pcPlanEnvCase" :rows="4" placeholder="请输入规划环评开展情况" type="textarea"/>
            </el-form-item>
<!--            <el-form-item label="项目现状">
              <el-input v-model="form.pcStatus" :rows="4" placeholder="项目现状" type="textarea"/>
            </el-form-item>-->
          </div>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer tianjie_button" style="text-align: center;">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>


<script>
import {
  addConstruction,
  delConstruction,
  exportConstruction,
  getConstruction,
  listConstruction,
  updateConstruction
} from "@/api/enterprise/construction";
import hangye from '@/assets/hangye.json'
import {InfoItem} from "@/api/enterprise/info";
import {isIntegerNotMust} from "@/api/validate/validate";

export default {
  name: "Construction",
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      active: false,
      position: {},
      show: false,
      hangye: hangye,
      hangyeArr: [],
      from: {},
      markers: [
        {
          longitude: 113.67,
          latitude: 38.9,
          scenicName: 11,
          showFlag: false

        },
        {
          longitude: 113.67,
          latitude: 37.9,
          scenicName: 11,
          showFlag: false
        },
      ],
      name: "",
      scenicContent: "",
      markerPoint1: {lng: 108.95, lat: 34.35},
      str: [
        {
          markerPoint: {lng: 113.67, lat: 38.9},
          xianghao: "BADWQI32221",
          adds: "差分状态:N",
          time: "上报时间:2020/11/01 13:48",
        },
        {
          markerPoint: {lng: 118.52, lat: 31.79},
          xianghao: "ABCD873873",
          adds: "差分状态:Y",
          time: "上报时间:2020/11/23 13:48",
        },
        {
          markerPoint: {lng: 116.404, lat: 39.915},
          xianghao: "EERQSIA21",
          adds: "差分状态:N",
          time: "上报时间:2018/11/23 11:48",
        },
      ],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目建设管理表格数据
      constructionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      value: '',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pcName: null,
        pcCode: null,
        pcAddress: null,
        pcContent: null,
        pcCycle: null,
        pcEnvSectors: null,
        pcBuildProperties: null,
        pcNowPepNo: null,
        pcPlanEnvCase: null,
        pcPlanEnvCensors: null,
        pcNolinearEngLng: null,
        pcNolinearEngLat: null,
        pcLinearEngLngStar: null,
        pcLinearEngLngEnd: null,
        pcLinearEngLatStar: null,
        pcLinearEngLatEnd: null,
        pcEngLength: null,
        pcTotalInvestment: null,
        pcEnvironmentInvestment: null,
        pcInvestmentRatio: null,
        pcProjectStartTime: null,
        pcEinsatzZiel: null,
        pcIndustryType: null,
        pcApplicationCategory: null,
        pcPlanEnvFilename: null,
        pcStatus: null,
        pcPlanEnvReviewNum: null,
        pcBeginningReport: null,
        pcApproval: null,
        epId: null,
      },
      // 表单参数
      form: {},
      rules: {
        pcName: [
          {required: true, message: "建设项目名称不能为空", trigger: "blur"}
        ],
        pcCycle:[{validator:isIntegerNotMust,trigger:'blur'}],
        pcEngLength: [
          {
            pattern: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
            message: '请输入正确的格式,可保留两位小数'
          }
        ],
        pcTotalInvestment:[
          {
            pattern: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
            message: '请输入正确的格式,可保留两位小数'
          }
        ],
        pcEnvironmentInvestment:[
          {
            pattern: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
            message: '请输入正确的格式,可保留两位小数'
          }
        ]
      },
      typeOptions:[],
      typeOptions_hp:[],
    };
  },
  created() {
    this.getList();
    this.getDicts("jsxz").then(response => {
      this.typeOptions = response.data;
    });
    this.getDicts("hp").then(response => {
      this.typeOptions_hp = response.data;
    });
  },
  methods: {
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions_hp, row.pcApproval);
    },
    handleAddressFun(e, form, thsAreaCode) {
      this.hangyeArr = e;
      this.form.remark = this.hangyeArr.toString()

      if (e[0]) {
        this.form.pcEnvSectors = e[0]
      }
      if (e[1]) {
        this.form.pcEnvSectors = e[1]
      }
      if (e[2]) {
        this.form.pcEnvSectors = e[2]
      }
      let nodesObj = this.$refs['cascader'].getCheckedNodes()
    },
    /** 查询项目建设管理列表 */
    getList() {
      this.loading = true;
      const username = this.$store.state.user.name;
      InfoItem(username).then(res => {
        this.queryParams.epId = res.data.epId;
        listConstruction(this.queryParams).then(response => {
          this.constructionList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        pcId: null,
        pcName: null,
        pcCode: null,
        pcAddress: null,
        pcContent: null,
        pcCycle: null,
        pcEnvSectors: null,
        pcBuildProperties: null,
        pcNowPepNo: null,
        pcPlanEnvCase: null,
        pcPlanEnvCensors: null,
        pcNolinearEngLng: null,
        pcNolinearEngLat: null,
        pcLinearEngLngStar: null,
        pcLinearEngLngEnd: null,
        pcLinearEngLatStar: null,
        pcLinearEngLatEnd: null,
        pcEngLength: null,
        pcTotalInvestment: null,
        pcEnvironmentInvestment: null,
        pcInvestmentRatio: null,
        pcProjectStartTime: null,
        pcEinsatzZiel: null,
        pcIndustryType: null,
        pcApplicationCategory: null,
        pcPlanEnvFilename: null,
        pcStatus: null,
        pcPlanEnvReviewNum: null,
        pcBeginningReport: null,
        pcApproval: null,
        epId: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.pcId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    infoWindowClose(marker) {
      marker.showFlag = false
    },
    infoWindowOpen(marker) {
      marker.showFlag = true
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加项目建设管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const pcId = row.pcId || this.ids
      getConstruction(pcId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改成功";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.pcId != null) {
            updateConstruction(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            const username = this.$store.state.user.name;
            InfoItem(username).then(res => {
              if (res.hasOwnProperty("data")) {
                this.form.epId = res.data.epId;
              }
              addConstruction(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            })
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const pcIds = row.pcId || this.ids;
      this.$confirm('是否确认删除项目建设编号为"' + pcIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delConstruction(pcIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有项目建设数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportConstruction(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {
      });
    }
  }
};
</script>


<style scoped>
.content-left {
  width: 30%;
  float: left;
}

.content-middle {
  width: 30%;
  float: left;
  margin-left: 3%;
}

.content-right {
  width: 30%;
  float: left;
  margin-left: 3%;
}

.content-address {
  display: flex;
  width: 100%;

}

.app-container-construction {
  padding-left: 60px;
  padding-right: 60px;
}

.el-form-item {
  /* height: 80px; */
  margin-bottom: 30px;
  /*padding-bottom: 20px;*/
}

.map {
  width: 100%;
  height: 100vh;
}

.title2 {
  height: 40px;
}

.title2 span {
  display: inline-block;
  border-radius: 50%;
  width: 15px;
  height: 15px;
  vertical-align: middle;
  margin-right: 10px;
  background-color: deepskyblue;
}

.clearfix:after {
  content: "020";
  display: block;
  height: 0;
  clear: both;
}

.el-upload {
  width: 7% !important;
}
</style>
